﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SimpleTaskSystem;

public class PromptAudio : MonoBehaviour
{
    public AudioSource audioSource;
    public string demoName;
    TaskManager taskManager;
    public void PlayAudio(AudioClip clip)
    {
        audioSource.Stop();
        audioSource.PlayOneShot(clip);
    }
    private void Awake()
    {
        taskManager = FindObjectOfType<TaskManager>();
    }
    private void Start()
    {
        SetAudio();
    }

    void SetAudio()
    {
        foreach (var task in taskManager.tasks)
        {
            if (!task.isAutomatic)
            {
                foreach (var operation in task.operations)
                {
                    //if (!operation.isAutomatic)
                    {
                        string path = demoName + "操作提示/" + operation.operationName;
                        AudioClip clip = (AudioClip)Resources.Load(path);
                        if (clip)
                        {
                            operation.onReadyAction.AddListener(delegate () { PlayAudio(clip); });
                        }
                    }
                }
            }
        }
    }
}
